package date0709am;

import java.sql.ResultSet;
import java.sql.SQLException;

import cn.edu.ecut.util.DatabaseType;
import cn.edu.ecut.util.JdbcHelper;
import cn.edu.ecut.util.RowMapper;

public class JdbcTest33 {

	public static void main(String[] args) throws SQLException {
		
		JdbcHelper h = JdbcHelper.getInstance( DatabaseType.ORACLE );
		
		String sql = "SELECT id , name , gender , birthdate FROM t_students WHERE id = ?" ;
		
		RowMapper<Student> rowMapper = new RowMapper<>() {
			@Override
			public Student wrap(ResultSet rs) throws SQLException {
				Student s = new Student();
				int id = rs.getInt( "id" );
				s.setId( id );
				String name = rs.getString( "name" );
				s.setName( name );
				String gender = rs.getString( "gender" );
				if( gender != null && gender.length() > 0 ) {
					char g = gender.charAt( 0 );
					s.setGender( g );
				}
				
				java.sql.Date date = rs.getDate( "birthdate" );
				if( date != null ) {
					s.setBirthdate( date.toLocalDate() );
				}
				return s;
			}
		} ;
		
		Student s = h.query( sql , rowMapper , 1111 );
		
		System.out.println( s );
		
		System.out.println( s.getName() );
		
		h.release();
		
	}

}
